No response compression when there is a referer#47751
No response compression when there is a referer#47751kobelb merged 10 commits intoelastic:masterfrom
Conversation
| throw new Error('Server is not created yet'); | ||
| } | ||
|
|
||
| this.server.ext('onRequest', (request, h) => { |
There was a problem hiding this comment.
I wasn't able to use registerOnPreAuth here because it doesn't expose the info. I'm assuming this generally isn't something we want to support, so I'm using the HapiJS interfaces directly. If you all think we should modify the KibanaRequest to include this, just let me know.
| registerRouter(router); | ||
|
|
||
| await server.start(); | ||
| const response = await innerServer.inject({ |
There was a problem hiding this comment.
I had to use .inject here, as opposed to how the other tests are using supertest with the listener or else I wasn't able to use response.request.info. I also wasn't able to look at response.headers['content-encoding'] because this isn't being set by Hapi...
There was a problem hiding this comment.
I don't feel great about testing implementation details rather than the actual HTTP response. It looks like supertest allows setting headers with the set method. Is it overriding it? If so, could we use a different way of sending a request in this test?
There was a problem hiding this comment.
I don't either... Even if I set the request headers, the response coming back from HapiJS doesn't have the Content-Encoding header set, even though it ends up having it in the functional tests...
There was a problem hiding this comment.
HapiJS seems to be skipping the actual compression in this situation, and it's not immediately obvious why: https://github.com/elastic/kibana/pull/47751/files#diff-51730cbab06a430a940f78fc9e710bd7R620-R637
There was a problem hiding this comment.
Hmm, maybe not worth figuring out why since we do at least the functional test which covers the blackbox behavior.
There was a problem hiding this comment.
I can look into it further to try to understand why. I gave up more easily than I usually do because.... hapi...
💔 Build Failed |
| registerRouter(router); | ||
|
|
||
| await server.start(); | ||
| const response = await innerServer.inject({ |
There was a problem hiding this comment.
Hmm, maybe not worth figuring out why since we do at least the functional test which covers the blackbox behavior.
|
|
||
| const router = new Router('', logger, enhanceWithContext); | ||
| router.get({ path: '/', validate: false }, (context, req, res) => | ||
| res.ok({ body: 'hello', headers: { 'Content-Type': 'text/html; charset=UTF-8' } }) |
There was a problem hiding this comment.
I believe there is threshold 1kB to enable gzip. Should fix the problem:
body: 'hello'.repeat(500), | await supertest(innerServer.listener) | ||
| .get('/') | ||
| .set('accept-encoding', 'gzip') | ||
| .then(response => { |
There was a problem hiding this comment.
can we avoid mixing async/await and promise syntax?
const response = await supertest(...);There was a problem hiding this comment.
It's rather prevalent within this file, but sure!
mshustov
left a comment
There was a problem hiding this comment.
Let's switch to http interface instead of using hapi specific API.
To be able to use |
|
@kobelb sorry, I mean for tests. implementation is ok |
💔 Build Failed |
|
|
||
| const router = new Router('', logger, enhanceWithContext); | ||
| router.get({ path: '/', validate: false }, (context, req, res) => | ||
| res.ok({ body: 'hello'.repeat(500), headers: { 'Content-Type': 'text/html; charset=UTF-8' } }) |
There was a problem hiding this comment.
shall we add a comment why we make such a long body?
There was a problem hiding this comment.
Yup, great idea. I will make it so.
💔 Build Failed |
💚 Build Succeeded |
|
@elasticmachine merge upstream |
💚 Build Succeeded |
* Hacking it in there, this is obviously not where this belongs * Moving implementation to a private method * Adding unit tests, I don't like the way I had to write these * Adding integration tests * Test not relying on implementation details... * No longer using .inject, thanks Mikhail!!! * Adding comment explaining the long body * Fixing nesting of describes for api integration tests
* Hacking it in there, this is obviously not where this belongs * Moving implementation to a private method * Adding unit tests, I don't like the way I had to write these * Adding integration tests * Test not relying on implementation details... * No longer using .inject, thanks Mikhail!!! * Adding comment explaining the long body * Fixing nesting of describes for api integration tests
* Hacking it in there, this is obviously not where this belongs * Moving implementation to a private method * Adding unit tests, I don't like the way I had to write these * Adding integration tests * Test not relying on implementation details... * No longer using .inject, thanks Mikhail!!! * Adding comment explaining the long body * Fixing nesting of describes for api integration tests
* Hacking it in there, this is obviously not where this belongs * Moving implementation to a private method * Adding unit tests, I don't like the way I had to write these * Adding integration tests * Test not relying on implementation details... * No longer using .inject, thanks Mikhail!!! * Adding comment explaining the long body * Fixing nesting of describes for api integration tests
This reverts commit 85e5885.
…" (elastic#49987) This reverts commit 85e5885.
When there is a "referer", this disables response compression.